﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Web.Mvc;
using System.Diagnostics;

namespace Lilium.Web.Mvc.AjaxControlToolkit
{
	internal sealed class EmbeededToolkitScriptResource: EmbeededScriptResource
	{
		public EmbeededToolkitScriptResource(
			string name, 
			Assembly resourceAssembly, 
			string resourceName, 
			string contentType,
			OutputCachePolicy cachePolicy,
			IEnumerable<ClientScriptResource> clientScriptResources)
			: base(name, resourceAssembly, resourceName, contentType, cachePolicy)
		{
			if (clientScriptResources == null)
				throw new ArgumentNullException("clientScriptResources");

			m_ClientScriptResources = clientScriptResources.ToArray();
		}


		protected override void OnProcessRequest(ControllerContext context)
		{
			base.OnProcessRequest(context);
			foreach (var clientScriptResource in ClientScriptResources)
				clientScriptResource.ProcessRequest(context);
		}

		#region private ClientScriptResource[] ClientScriptResources

		private readonly ClientScriptResource[] m_ClientScriptResources;

		private ClientScriptResource[] ClientScriptResources { [DebuggerNonUserCodeAttribute] get { return m_ClientScriptResources; } }

		#endregion
	}
}
